package net.oschina.allchat.protocol.core.stanza;

import java.util.UUID;

import net.oschina.allchat.protocol.core.Protocol;


public final class Iq extends Stanza {
	public enum Type {
		RESULT,
		SET,
		GET,
		ERROR
	}
	
	public static final Protocol PROTOCOL = new Protocol("iq");
	
	private Iq.Type type;
	
	public Iq() {
		this(null);
	}
	
	public Iq(Iq.Type type) {
		this(type, null);
	}
	
	public Iq(Iq.Type type, String id) {
		this.type = type;
		
		if (this.type == null) {
			this.type = Iq.Type.GET;
		}
		
		if (id != null) {
			setId(id);
		} else {
			setId(Long.toHexString(UUID.randomUUID().getLeastSignificantBits()).substring(4, 12));
		}
	}
	
	public Iq.Type getType() {
		return type;
	}
	
	public void setType(Iq.Type type) {
		this.type = type;
	}
}
